﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TreeGraphicalControl;
using FeatureModelTool.ProjectView.ProjectTreeStructures;
using Collections.TreeCollections;
using System.Windows.Controls;
using FeatureModelTool.ProjectView.MenuItems;
using System.Windows;
using FeatureModelTool.Windows;
using System.Windows.Media;

namespace FeatureModelTool.ProjectView.TreeItems
{
    public class TreeItem_ProjectFolder : TreeViewItemControl
    {
        #region Properties
        public ProjectFolder ProjectTreeInstance { get; protected set; }
        #endregion

        private readonly static string _ICON_SOURCE = "/FeatureModelTool;component/Images/folder_close.png";

        public TreeItem_ProjectFolder(ProjectFolder folder)
            : base()
        {
            ProjectTreeInstance = folder;
            this.Header = MainWindow.GenerateTreeItemHeader(folder.Name, _ICON_SOURCE,
                Brushes.White);
        }

        /// <summary>
        /// Tree Item Construct
        /// </summary>
        /// <param name="treeObj"></param>
        /// <returns></returns>
        public static TreeViewItemControl ConstructTreeItem(TreeObject treeObj)
        {
            ProjectFolder projFolder = treeObj as ProjectFolder;
            if (projFolder == null)
            {
                return null;
            }
            return new TreeItem_ProjectFolder(projFolder);
        }

        #region Context Menu
        /// <summary>
        /// 
        /// </summary>
        /// <param name="tree"></param>
        /// <returns></returns>
        public static ContextMenu ContextGenerator(TreeViewItemControl treeItem, TreeObject treeObj)
        {
            ProjectFolder projFolder = treeObj as ProjectFolder;
            TreeItem_ProjectFolder treeItem_Folder = treeItem as TreeItem_ProjectFolder;
            if (projFolder == null)
            {
                return null;
            }
            ContextMenu menu = new ContextMenu();

            // new feature Model file
            MenuItem_Folder newFeatureModel = new MenuItem_Folder(treeItem_Folder, 
                (ProjectTree)projFolder.TreeOwner, projFolder)
            {
                Name = projFolder.ID.ToString(),
                Header = "New File"
            };
            newFeatureModel.Click += new RoutedEventHandler(TreeItem_ProjectTreeRoot.NewFile_EventHandler);

            MenuItem_Folder addFile = new MenuItem_Folder(treeItem_Folder, (ProjectTree)projFolder.TreeOwner, projFolder)
            {
                Name = projFolder.ID.ToString(),
                Header = "Add Existed File",
            };

            MenuItem_Folder newFolder = new MenuItem_Folder(treeItem_Folder, (ProjectTree)projFolder.TreeOwner, projFolder)
            {
                Name = projFolder.ID.ToString(),
                Header = "New Folder"
            };
            newFolder.Click += new RoutedEventHandler(TreeItem_ProjectTreeRoot.NewFolder_EventHandler);

            menu.Items.Add(newFolder);
            menu.Items.Add(new Separator());
            menu.Items.Add(addFile);
            menu.Items.Add(newFeatureModel);

            return menu;
        }
        #endregion

    }
}
